const config = require("../config");
const model = require("../model");
const Studio = model.Studio;

module.exports = {

  create: async (data) => {
    let result = await Studio.create(data);
    if (result) {
      return {
        "result": true,
        "data": result
      };
    } else return { "result": false, }
  },

  getById: async (id) => {
    let result = await Studio.findById(id);
    if (result) {
      return {
        "result": true,
        "data": result
      };
    } else return { "result": false, }
  },

  getAll: async () => {
    let result = await Studio.findAll({
      where: {}
    });
    if (result) {
      return {
        "result": true,
        "data": result
      };
    } else return { "result": false, }
  },

  deleteById: async (id) => {
    if (await Studio.destroy({ where: { id: id } })) {
      return {
        "result": true,
      };
    } else return { "result": false, }
  },

  updatePropById: async (propName, id, data) => {
    let result = await Studio.update(JSON.parse( `{"${propName}":"${data}"}` ), {
      where: { id: id }
    });
    if (result[0] === 1) {
      return {
        "result": true,
      };
    } else return { "result": false, }
  },

  // updateStructById: async (id, struct) => {
  //   let result = await Studio.update({
  //     struct: struct
  //   }, {
  //       where: { id: id }
  //     });
  //   if (result[0] === 1) {
  //     return {
  //       "result": true,
  //     };
  //   } else return { "result": false, }
  // },

}
